/**
 * 返回一个帧数数组nums中拥有最大和的连续子数组， 返回它的和
 */

function maxSubArray(nums) {

    let max = nums[0]
    let sum = 0;

    for (let num of nums) {
        if (sum < 0) {
            sum = 0
        }
        sum += num
        max = Math.max(sum, max)
    }
    return max;
}

const nums = [1, 3, 4, 0, 10, 90, -10, -19, 19]

console.log(maxSubArray(nums))

function maxStr(arr) {
    let sum = arr[0]
    let max = 0

    for (let item of arr) {
        if (sum < 0) sum = 0
        sum += item
        max = Math.max(sum, max)
    }
    return max
}

console.log(maxStr(nums));




